<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head>
    <meta charset="UTF-8">
    <title>武钢有限组织绩效</title>
    <link href="../static/css/todostyle.css" rel="stylesheet" th:href="@{/css/todostyle.css}"/>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/font-awesome.min.css}"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link rel="stylesheet" th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/libs/bootstrap-treetable/bootstrap-treetable.css}"/>
    <link rel="stylesheet"
          th:href="@{/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.css}"/>
    <link rel="stylesheet" th:href="@{/css/animate.css}"/>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/libs/select/select2.css}"/>
    <link rel="stylesheet" th:href="@{/ruoyi/css/ry-ui.css}"/>
</head>
<style>
    #table tbody tr:nth-child(even) {
        background: #E1F9FF;
    }

    .import {
        margin: 80px 50px 0 0 ! important;
    }

    #table th {
        width: 100px;
    }

    #table td {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 15px
    }

    /* #table td:hover ~ td{overflow: visible;  white-space: normal;}
    #table td:hover{overflow: visible;   white-space: normal;} */
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <input id="approverId" name="approverId" th:value="${approverId}" type="hidden">
    <input id="tableId" name="tableId" th:value="${tableId}" type="hidden"><!-- 待办人员角色 -->
    <input id="projectType" name="projectType" th:value="${projectType}" type="hidden">
    <input id="approverCode" name="approverCode" th:value="${approverCode}" type="hidden">
    <!--<a class="btn btn-success" onclick="doAddDefendIndex()">
        <i class="fa fa-plus"></i>添加
    </a>-->
    <table data-mobile-responsive="true" id="tableIndex">
        <!-- 在此处填充表格数据 -->
    </table>
</div>
<div th:include="include::footer"></div>
<script charset="gb2312" th:src="@{/js/rule.js}" type="text/javascript"></script>
<script type="text/javascript">
    var prefix = ctx + "zzjx/pefctasstable"
    var cols = [];
    $(function () {
        var approverId = $("#approverId").val();
        var tableId = $("#tableId").val();
        var projectType = $("#projectType").val();
        var approverCode = $("#approverCode").val();
        if (tableId != "") {
            $.modal.loading("请等待加载预览信息!");
            var url_ = "";
            var datas = {};
            if (projectType == "ldzhpj") {
                url_ = ctx + "zzjx/pefctasstable/previewForLdzhpj";
                datas = {"tableId": tableId, "id": approverId, "approverCode": approverCode};
            } else {
                url_ = ctx + "zzjx/pefctasstable/preview";
                datas = {"tableId": tableId, "id": approverId};
            }
            $.ajax({
                url: url_
                , data: datas
                , dataType: "JSON"
                , type: "GET"
                , async: true
                , success: function (result) {
                    $.table.destroy("tableIndex");
                    debugger
                    if (projectType == "ldzhpj") {
                        buildTableLD($('#tableIndex'), result);
                        $.modal.closeLoading();
                    } else {
                        var dictData = result.dictData;
                        var list = result.list;
                        buildTable($('#tableIndex'), dictData.length, list.length, dictData, list);
                        $.modal.closeLoading();
                    }
                    $('input[type="text"]').attr('disabled', 'disabled');
                    $('input[type="radio"]').attr('disabled', 'disabled');
                    $('textarea').attr('disabled', 'disabled');
                    $('select').attr('disabled', 'disabled');
                }, error: function () {
                    $.modal.closeLoading();
                    $.modal.alertError("获取预览信息失败!");
                }
            })
            $("#tableDiv").removeClass("hidden");
            return false;
        }
        $("#tableDiv").addClass("hidden");
    })

    function buildTable($el, cells, rows, dictData, list) {
        var roleId = $("#roleId").val();
        var i, j, row, columns = [], data = [];
        columns.push({
            checkbox: true
        })
        columns.push({
            field: "id",
            title: "ID",
            visible: false
        })
        //拼接table,拼接表头
        for (var dd in dictData) {
            var dictLabel = dictData[dd]["dictLabel"];//显示名称
            var dictValue = dictData[dd]["dictValue"];//字段值
            var listClass = dictData[dd]["listClass"];//列显示类型(输入框，下拉框，显示)
            var isMustFill = dictData[dd]["isMustFill"];//是否为空
            var fillRoleIds = dictData[dd]["fillRoleIds"];//可评角色ID
            var f = {
                field: dictValue,
                title: dictLabel,
                sortable: false,
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }
            var opt = {
                dictLabel: dictLabel,	//必填
                dictValue: dictValue,	//必填
                tableId: "table",		//必填
                ruleId: listClass,		//必填
                align: "center",
                halign: "center",
                roleId: roleId,			//必填
                isMustFill: isMustFill,	//必填
                fillRoleIds: fillRoleIds,//必填
                formId: "formTable",		//必填
            };
            f = $.rule.fmRule(opt);
            columns.push(f);
            cols = columns;
        }
        $el.bootstrapTable('destroy').bootstrapTable({
            columns: columns,
            uniqueId: "id",
            data: list,
            search: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            showExport: false,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.
            height: 600,
            pagination: false,
            modalName: "考核指标",
            onPostBody: function (data) {
                /*bding();*/
            },
            onDblClickRow: function (row) {
                console.log("click:" + JSON.stringify(row))
            }
        });
    }

    /**
     * 构建预览信息表格
     * @param $el        table对象
     * @param list        行数据
     */
    function buildTableLD($el, list) {
        var columns = [
            [{
                checkbox: true,
                rowspan: 2,
                colspan: 1
            }, {
                field: "id",
                title: "ID",
                visible: false,
                rowspan: 2,
                colspan: 1
            }, {
                field: 'indName',
                title: '被评价部门',
                rowspan: 2,
                colspan: 1,
                align: 'center',
                halign: 'center',
                width: 10
            }, {
                field: 'target1',
                title: '满意度得分',
                rowspan: 2,
                colspan: 1,
                align: 'center',
                halign: 'center',
                width: 10
            }, {
                field: 'gzjhTableId',
                title: '重点工作评价',
                rowspan: 2,
                colspan: 1,
                align: 'center',
                halign: 'center',
                width: 12,
                formatter: function (value, row, index) {
                    if (value == "" || typeof (value) == "undefined") {
                        return "";
                    } else {
                        return '<a  onclick="viewResult(\'' + value + '\',\'zdgz\')" >查看</a>';
                    }
                }
            }, {
                field: 'fileList',
                title: '年度工作总结',
                halign: 'center',
                rowspan: 2,
                colspan: 1,
                width: 17,
                formatter: function (value, row, index) {
                    if (value == "" || typeof (value) == "undefined") {
                        return "";
                    } else {
                        var html = ""
                        var l = value.length;
                        if (l > 0) {
                            for (var i = 0; i < l; i++) {
                                html += "<a onclick='checkFile(\"" + value[i].filePath + "\")'>" + value[i].fileName + "</a>";
                                html += "<br>";
                            }
                        }
                        return html;
                    }
                }
            }, {
                field: 'fmqdKf',
                title: '负面清单扣分',
                rowspan: 2,
                colspan: 1,
                align: 'center',
                halign: 'center',
                width: 10/*,
                    formatter: function (value, row , index) {
                        var id = row.id;
						var projectId = row.projectId;
                        return '<a  onclick="viewResult2(\''+projectId+'\',\'fmqd\')" >查看</a>';
                    }*/
            }, {
                title: '综合评价',
                align: 'center',
                colspan: 5,
                rowspan: 1,
                width: 32
            }],
            [{
                field: 'resultYx',
                title: '优秀',
                align: 'center',
                formatter: function (value, row, index) {
                    debugger
                    var name = "result" + row.id;
                    if (row.target == "5") {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",5)' value='5' name='" + name + "' checked>";
                    } else {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",5)' value='5' name='" + name + "'>"
                    }
                }
            }, {
                field: 'resultLh',
                title: '良好',
                align: 'center',
                formatter: function (value, row, index) {
                    var name = "result" + row.id;
                    if (row.target == "4.5") {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",4.5)' value='4.5' name='" + name + "' checked>";
                    } else {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",4.5)' value='4.5' name='" + name + "'>"
                    }
                }
            }, {
                field: 'resultYb',
                title: '一般',
                align: 'center',
                formatter: function (value, row, index) {
                    var name = "result" + row.id;
                    if (row.target == "4") {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",4)' value='4' name='" + name + "' checked>";
                    } else {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",4)' value='4' name='" + name + "'>"
                    }
                }
            }, {
                field: 'resultDgj',
                title: '待改进',
                align: 'center',
                formatter: function (value, row, index) {
                    var name = "result" + row.id;
                    if (row.target == "3") {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",3)' value='3' name='" + name + "' checked>";
                    } else {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",3)' value='3' name='" + name + "'>"
                    }
                }
            }, {
                title: '不合格',
                field: 'resultBhg',
                align: 'center',
                formatter: function (value, row, index) {
                    var name = "result" + row.id;
                    if (row.target == "2") {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",2)' value='2' name='" + name + "' checked>";
                    } else {
                        return "<input class='required' type='radio' onclick='updateDate(" + index + ",2)' value='2' name='" + name + "'>"
                    }
                }
            }, {
                field: 'target',
                title: '结果',
                align: 'center',
                visible: false,
            }]
        ];
        cols = columns;
        //构建表格
        $el.bootstrapTable('destroy').bootstrapTable({
            columns: columns,
            data: list,
            search: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            showExport: false,                     //是否显示导出
            height: 600,
            pagination: false,
            modalName: "考核指标"
        });
    }

    function doAddDefendIndex() {
        var row = $.map($('#tableIndex').bootstrapTable('getSelections'), function (row) {
            return row;
        });
        if (row.length != 1) {
            $.modal.alertError("请选择一条数据!");
            return false;
        }
        return row;
    }

    function checkFile(obj) {
        var filePath = obj;
        debugger
        if (filePath != "") {
            var fileLastName = filePath.substring(filePath.lastIndexOf("\."), filePath.length);
            var strRegex = "(.xls|.xlsx|.ppt|.pptx|.pdf|.doc|.docx)$"; //用于验证扩展名的正则表达式
            var picRegex = "(.jpg|.png|.gif|.ps|.jpeg)$";
            var re = new RegExp(strRegex);
            var rePic = new RegExp(picRegex);
            if (re.test(fileLastName.toLowerCase())) {
                $.modal.loading("正在生成预览文件，请稍后...");
                $.ajax({
                    async: true,
                    type: "post",
                    url: ctx + "zzjx/projectSysfile/files2Pdf?filePath=" + filePath,
                    success: function (data) {
                        //layer.msg('操作成功！');
                        console.log(data);
                        if (data.toString().indexOf("/") > 0) {
                            var filePath = data.substring(data.toString().indexOf("profile/"), data.length);
                            window.open(ctx + "js/web/viewer.html?file=" + ctx + filePath);
                        }
                        $.modal.closeLoading();
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg('操作失败！');
                        $.modal.closeLoading();
                    }
                });
            } else if (rePic.test(fileLastName.toLowerCase())) {
                var filePath2 = filePath.substring(filePath.toString().indexOf("profile/"), filePath.length);
                window.open(ctx + filePath2);
            } else {
                $.modal.confirm("该文件不可进行预览!是否下载?", function () {
                    downloadFile(obj);
                });
            }
        }
    }

    function downloadFile(id, name) {
        window.location.href = ctx + "zzjx/projectSysfile/downloadFile?filePath=" + id + "&fileName=" + name;
    }
</script>
</body>
</html>
